package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.dto.QuestionFormDTO;
import com.tianji.learning.domain.query.QuestionPageQuery;
import com.tianji.learning.domain.vo.QuestionVO;
import com.tianji.learning.service.IInteractionQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 互动提问的问题表 前端控制器
 * </p>
 *
 * @author waker
 * @since 2025-10-25
 */
@Api(tags = "用户端-问题相关接口")
@RestController
@RequestMapping("/questions")
@RequiredArgsConstructor
public class InteractionQuestionController {

    private final IInteractionQuestionService questionService;

    /**
     * 1. 新增互动问题
     * @param questionFormDTO
     */
    @PostMapping
    @ApiOperation("新增互动问题")
    public void saveQuestion(@RequestBody QuestionFormDTO questionFormDTO){
        questionService.saveQuestion(questionFormDTO);
    }

    /**
     * 2. 修改互动问题
     * @param id
     * @param questionFormDTO
     */
    @PutMapping("/{id}")
    @ApiOperation("修改互动问题")
    public void updateQuestion(@PathVariable("id") Long id,@RequestBody QuestionFormDTO questionFormDTO){
        questionService.updateQuestion(id,questionFormDTO);
    }

    /**
     * 3. 分页查询互动问题列表
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询互动问题列表")
    public PageDTO<QuestionVO> pageQuery(QuestionPageQuery query){
        return questionService.pageQuery(query);
    }

    /**
     * 4. 根据id查询问题详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询问题详情")
    public QuestionVO queryQuestionById(@PathVariable("id") Long id){
        return questionService.queryQuestionById(id);
    }

    /**
     * 5. 删除我的问题
     * @param id
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除我的问题")
    public void deleteQuestionById(@PathVariable("id") Long id){
        questionService.deleteQuestionById(id);
    }

}
